//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "InterestRateIndex.h"
using namespace Cephei::QL::Indexes;
#include <gen/QL/Currency.h>
#include <gen/QL/Times/DayCounter.h>
#include <gen/QL/Times/Calendar.h>
#include <gen/QL/Times/Period.h>
#include <gen/QL/Index.h>
using namespace Cephei::QL;
using namespace Cephei::QL::Times;
#define HANDLE
#define ABSTRACT
#undef STRUCT
Cephei::QL::Indexes::CInterestRateIndex::CInterestRateIndex (boost::shared_ptr<QuantLib::InterestRateIndex>& childNative, Object^ owner) : CIndex(CInterestRateIndex::typeid)
{
#ifdef HANDLE
	_phInterestRateIndex = NULL;
#endif
	_ppInterestRateIndex = &childNative;
    _ppIndex = new boost::shared_ptr<QuantLib::Index> (boost::dynamic_pointer_cast<QuantLib::Index> (*_ppInterestRateIndex));
}
Cephei::QL::Indexes::CInterestRateIndex::CInterestRateIndex (QuantLib::InterestRateIndex& childNative, Object^ owner) : CIndex(CInterestRateIndex::typeid)
{
#ifdef HANDLE
	_phInterestRateIndex = NULL;
#endif
	_ppInterestRateIndex = new boost::shared_ptr<QuantLib::InterestRateIndex> (&childNative);
    _ppIndex = new boost::shared_ptr<QuantLib::Index> (boost::dynamic_pointer_cast<QuantLib::Index> (*_ppInterestRateIndex));
    _InterestRateIndexOwner = owner;
    _IndexOwner = owner;
}

Cephei::QL::Indexes::CInterestRateIndex::CInterestRateIndex (CInterestRateIndex^ copy) : CIndex(CInterestRateIndex::typeid)
{
#ifdef HANDLE
	_phInterestRateIndex = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppInterestRateIndex = new boost::shared_ptr<QuantLib::InterestRateIndex> (copy->GetShared());
        _ppIndex = new boost::shared_ptr<QuantLib::Index> (boost::dynamic_pointer_cast<QuantLib::Index> (*_ppInterestRateIndex));
    }
}
Cephei::QL::Indexes::CInterestRateIndex::CInterestRateIndex (System::Type^ t) : CIndex(CInterestRateIndex::typeid)
{
#ifdef HANDLE
	_phInterestRateIndex = NULL;
#endif
	if (!t->IsSubclassOf(CInterestRateIndex::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Indexes::CInterestRateIndex::CInterestRateIndex (QuantLib::Handle<QuantLib::InterestRateIndex>& childNative, Object^ owner)  : CIndex(CInterestRateIndex::typeid)
{
	_phInterestRateIndex = &childNative;
	_ppInterestRateIndex = &static_cast<boost::shared_ptr<QuantLib::InterestRateIndex>>(childNative.currentLink());
    _ppIndex = new boost::shared_ptr<QuantLib::Index> (boost::dynamic_pointer_cast<QuantLib::Index> (*_ppInterestRateIndex));
    _InterestRateIndexOwner = owner;
}
Cephei::QL::Indexes::CInterestRateIndex::CInterestRateIndex (QuantLib::Handle<QuantLib::InterestRateIndex> childNative)  : CIndex(CInterestRateIndex::typeid)
{
	_phInterestRateIndex = &childNative;
	_ppInterestRateIndex = &static_cast<boost::shared_ptr<QuantLib::InterestRateIndex>>(childNative.currentLink());
    _ppIndex = new boost::shared_ptr<QuantLib::Index> (boost::dynamic_pointer_cast<QuantLib::Index> (*_ppInterestRateIndex));
}
#endif
#ifdef STRUCT
Cephei::QL::Indexes::CInterestRateIndex::CInterestRateIndex (QuantLib::InterestRateIndex childNative)  : CIndex(CInterestRateIndex::typeid)
{
#ifdef HANDLE
	_phInterestRateIndex = NULL;
#endif
	_ppInterestRateIndex = new boost::shared_ptr<QuantLib::InterestRateIndex> (new QuantLib::InterestRateIndex (childNative));
    _ppIndex = new boost::shared_ptr<QuantLib::Index> (boost::dynamic_pointer_cast<QuantLib::Index> (*_ppInterestRateIndex));
}
#endif

Cephei::QL::Indexes::CInterestRateIndex::~CInterestRateIndex ()
{
    if (_ppInterestRateIndex != NULL)
    {
	    delete _ppInterestRateIndex;
        _ppInterestRateIndex = NULL;
    }
}
Cephei::QL::Indexes::CInterestRateIndex::!CInterestRateIndex ()
{
    if (_ppInterestRateIndex != NULL)
    {
	    delete _ppInterestRateIndex;
    }
}
QuantLib::InterestRateIndex& Cephei::QL::Indexes::CInterestRateIndex::GetReference ()
{
    if (_ppInterestRateIndex == NULL) throw gcnew NativeNullException ();
	return **_ppInterestRateIndex;
}
boost::shared_ptr<QuantLib::InterestRateIndex>& Cephei::QL::Indexes::CInterestRateIndex::GetShared ()
{
    if (_ppInterestRateIndex == NULL) throw gcnew NativeNullException ();
	return *_ppInterestRateIndex;
}
QuantLib::InterestRateIndex* Cephei::QL::Indexes::CInterestRateIndex::GetPointer ()
{
    if (_ppInterestRateIndex == NULL) throw gcnew NativeNullException ();
	return &**_ppInterestRateIndex;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::InterestRateIndex>& Cephei::QL::Indexes::CInterestRateIndex::GetHandle ()
{
	if (_phInterestRateIndex == NULL)
	{
		_phInterestRateIndex = new Handle<QuantLib::InterestRateIndex> (*_ppInterestRateIndex);
	}
	return *_phInterestRateIndex;
}
#endif
bool Cephei::QL::Indexes::CInterestRateIndex::HasNative () 
{
	return (_ppInterestRateIndex != NULL);
}

Cephei::QL::ICurrency^ Cephei::QL::Indexes::CInterestRateIndex::Currency::get ()
{
    try
    {
    	QuantLib::Currency& _rv = (QuantLib::Currency&)(*_ppInterestRateIndex)->currency ( );   
        Cephei::QL::CCurrency^ _nrv = gcnew Cephei::QL::CCurrency (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::IDayCounter^ Cephei::QL::Indexes::CInterestRateIndex::DayCounter::get ()
{
    try
    {
    	QuantLib::DayCounter& _rv = (QuantLib::DayCounter&)(*_ppInterestRateIndex)->dayCounter ( );   
        Cephei::QL::Times::CDayCounter^ _nrv = gcnew Cephei::QL::Times::CDayCounter (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
String^ Cephei::QL::Indexes::CInterestRateIndex::FamilyName::get ()
{
    try
    {
    	std::string _rv = (std::string)(*_ppInterestRateIndex)->familyName ( );   
        String^ _nrv = (String^)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Indexes::CInterestRateIndex::Fixing (DateTime fixingDate, Microsoft::FSharp::Core::FSharpOption<Boolean>^ forecastTodaysFixing)
{
    try
    {
        QuantLib::Date _fixingDate = (QuantLib::Date)ValueHelper::Convert (fixingDate);
        bool _forecastTodaysFixing = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (forecastTodaysFixing) ? (bool)ValueHelper::Convert (forecastTodaysFixing->Value) : false); //9a
    	QuantLib::Rate _rv = (QuantLib::Rate)(*_ppInterestRateIndex)->fixing ( _fixingDate,  _forecastTodaysFixing );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::ICalendar^ Cephei::QL::Indexes::CInterestRateIndex::FixingCalendar::get ()
{
    try
    {
    	QuantLib::Calendar _rv = (QuantLib::Calendar)(*_ppInterestRateIndex)->fixingCalendar ( );   
        Cephei::QL::Times::CCalendar^ _nrv = gcnew Cephei::QL::Times::CCalendar (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
DateTime Cephei::QL::Indexes::CInterestRateIndex::FixingDate (DateTime valueDate)
{
    try
    {
        QuantLib::Date _valueDate = (QuantLib::Date)ValueHelper::Convert (valueDate);
    	QuantLib::Date _rv = (QuantLib::Date)(*_ppInterestRateIndex)->fixingDate ( _valueDate );   
        DateTime _nrv = (DateTime)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
UInt32 Cephei::QL::Indexes::CInterestRateIndex::FixingDays::get ()
{
    try
    {
    	QuantLib::Natural _rv = (QuantLib::Natural)(*_ppInterestRateIndex)->fixingDays ( );   
        UInt32 _nrv = (UInt32)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Boolean Cephei::QL::Indexes::CInterestRateIndex::IsValidFixingDate (DateTime fixingDate)
{
    try
    {
        QuantLib::Date _fixingDate = (QuantLib::Date)ValueHelper::Convert (fixingDate);
    	bool _rv = (bool)(*_ppInterestRateIndex)->isValidFixingDate ( _fixingDate );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
DateTime Cephei::QL::Indexes::CInterestRateIndex::MaturityDate (DateTime valueDate)
{
    try
    {
        QuantLib::Date _valueDate = (QuantLib::Date)ValueHelper::Convert (valueDate);
    	QuantLib::Date _rv = (QuantLib::Date)(*_ppInterestRateIndex)->maturityDate ( _valueDate );   
        DateTime _nrv = (DateTime)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
String^ Cephei::QL::Indexes::CInterestRateIndex::Name::get ()
{
    try
    {
    	std::string _rv = (std::string)(*_ppInterestRateIndex)->name ( );   
        String^ _nrv = (String^)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::IPeriod^ Cephei::QL::Indexes::CInterestRateIndex::Tenor::get ()
{
    try
    {
    	QuantLib::Period _rv = (QuantLib::Period)(*_ppInterestRateIndex)->tenor ( );   
        Cephei::QL::Times::CPeriod^ _nrv = gcnew Cephei::QL::Times::CPeriod (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Indexes::IInterestRateIndex^ Cephei::QL::Indexes::CInterestRateIndex::Update::get ()
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
    	(*_ppInterestRateIndex)->update ( );
    	return this;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
DateTime Cephei::QL::Indexes::CInterestRateIndex::ValueDate (DateTime fixingDate)
{
    try
    {
        QuantLib::Date _fixingDate = (QuantLib::Date)ValueHelper::Convert (fixingDate);
    	QuantLib::Date _rv = (QuantLib::Date)(*_ppInterestRateIndex)->valueDate ( _fixingDate );   
        DateTime _nrv = (DateTime)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Indexes::CInterestRateIndexVector::CInterestRateIndexVector ()
{
#ifdef STRUCT
	_pVValue = NULL;
#endif
	_pVBoost = NULL;
#ifdef HANDLE
	_pVHand = NULL;
#endif
}
Cephei::QL::Indexes::CInterestRateIndexVector::~CInterestRateIndexVector ()
{
#ifdef STRUCT
	if (_pVValue != NULL) delete _pVValue;
	_pVValue = NULL;
#endif   
	if (_pVBoost != NULL) delete _pVBoost;
	_pVBoost = NULL;
#ifdef HANDLE
	if (_pVHand != NULL) delete _pVHand;
	_pVHand = NULL;
#endif
}
Cephei::QL::Indexes::CInterestRateIndexVector::!CInterestRateIndexVector ()
{
#ifdef STRUCT
	if (_pVValue != NULL) delete _pVValue;
#endif   
	if (_pVBoost != NULL) delete _pVBoost;
#ifdef HANDLE
	if (_pVHand != NULL) delete _pVHand;
#endif
}
#ifdef STRUCT
Cephei::QL::Indexes::CInterestRateIndexVector::CInterestRateIndexVector (std::vector<QuantLib::InterestRateIndex>& vec, Object^ owner)
{
#ifdef STRUCT
	_pVValue = NULL;
#endif
	_pVBoost = NULL;
#ifdef HANDLE
	_pVHand = NULL;
#endif
	_pVValue = &vec;
	_owner = owner;
}
Cephei::QL::Indexes::CInterestRateIndexVector::CInterestRateIndexVector (std::vector<QuantLib::InterestRateIndex> vec)
{
#ifdef STRUCT
	_pVValue = NULL;
#endif
	_pVBoost = NULL;
#ifdef HANDLE
	_pVHand = NULL;
#endif
	_pVValue = new std::vector<QuantLib::InterestRateIndex> (vec);
}
#endif
Cephei::QL::Indexes::CInterestRateIndexVector::CInterestRateIndexVector (std::vector<boost::shared_ptr<QuantLib::InterestRateIndex>>& vec, Object^ owner)
{
#ifdef STRUCT
	_pVValue = NULL;
#endif
	_pVBoost = NULL;
#ifdef HANDLE
	_pVHand = NULL;
#endif
	 _pVBoost = &vec;
	_owner = owner;
}
#ifdef HANDLE
Cephei::QL::Indexes::CInterestRateIndexVector::CInterestRateIndexVector (std::vector<QuantLib::Handle<QuantLib::InterestRateIndex>>& vec, Object^ owner)
{
#ifdef STRUCT
	_pVValue = NULL;
#endif
	_pVBoost = NULL;
#ifdef HANDLE
	_pVHand = NULL;
#endif
	 _pVHand = &vec;
	_owner = owner;
}
#endif

int Cephei::QL::Indexes::CInterestRateIndexVector::Count::get ()
{
#ifdef STRUCT
	if (_pVValue != NULL) 
	{
		return _pVValue->size();
	}
#endif    
	if (_pVBoost != NULL)
	{
		return _pVBoost->size ();
	}
#ifdef HANDLE
	if (_pVHand != NULL)
	{
		return _pVHand->size ();
	}
#endif
	return 0;		// should never happen
}
Cephei::QL::Indexes::IInterestRateIndex^ Cephei::QL::Indexes::CInterestRateIndexVector::default::get (int index) 
{
#ifdef STRUCT
	if (_pVValue != NULL) 
	{
    	if ((size_t)index >= _pVValue->size()) throw gcnew RangeException ();
		QuantLib::InterestRateIndex& native = (*_pVValue)[index];
		return gcnew CInterestRateIndex (native, this);
	}
#endif    
	if (_pVBoost != NULL)
	{
    	if ((size_t)index >= _pVBoost->size()) throw gcnew RangeException ();
		QuantLib::InterestRateIndex& native = *(*_pVBoost)[index];
		return gcnew CInterestRateIndex (native, this);
	}
#ifdef HANDLE
	if (_pVHand != NULL)
	{
    	if ((size_t)index >= _pVHand->size()) throw gcnew RangeException ();
		QuantLib::InterestRateIndex& native = *((*_pVHand)[index].currentLink ());
		return gcnew CInterestRateIndex (native, this);
	}
#endif
	return nullptr;		// can never be the case
}
void Cephei::QL::Indexes::CInterestRateIndexVector::default::set (int index, Cephei::QL::Indexes::IInterestRateIndex^ value) 
{
#ifdef STRUCT
	if (_pVValue != NULL)
	{
		if (_pVValue->size() <= (size_t)index)
		{
			// can't happen because vectors are filled from List<> sequentially
			if (_pVValue->size() < (size_t)index)
			{
				throw gcnew RangeException ();
			}
			_pVValue->push_back (dynamic_cast<CInterestRateIndex^>(value)->GetReference ());
		}
        else
        {
            QuantLib::InterestRateIndex& c = (*_pVValue)[index];
            c = dynamic_cast<CInterestRateIndex^>(value)->GetReference ();
        }
	}
#endif   
	if (_pVBoost != NULL)
	{
		if (_pVBoost->size() <= (size_t)index)
		{
			// can't happen because vectors are filled from List<> sequentially
			if (_pVBoost->size() < (size_t)index)
			{
				throw gcnew RangeException ();
			}
			_pVBoost->push_back (dynamic_cast<CInterestRateIndex^>(value)->GetShared ());
		}
		boost::shared_ptr<QuantLib::InterestRateIndex>& c = (*_pVBoost)[index];
		c = dynamic_cast<CInterestRateIndex^>(value)->GetShared ();
	}
#ifdef HANDLE
	if (_pVHand != NULL)
	{
		if (_pVHand->size() <= (size_t)index)
		{
			// can't happen because vectors are filled from List<> sequentially
			if (_pVHand->size() < (size_t)index)
			{
				throw gcnew RangeException ();
			}
			_pVHand->push_back (QuantLib::Handle<QuantLib::InterestRateIndex> ());
		}
		QuantLib::Handle<QuantLib::InterestRateIndex>& c = (*_pVHand)[index];
		boost::shared_ptr<QuantLib::InterestRateIndex>& b = static_cast<boost::shared_ptr<QuantLib::InterestRateIndex>>(c.currentLink());
		b = dynamic_cast<CInterestRateIndex^>(value)->GetShared ();
	}
#endif
}
Cephei::Generic::ICell<Cephei::QL::Indexes::IInterestRateIndex^>^ Cephei::QL::Indexes::CInterestRateIndexVector::CItem::get (int index) 
{
	return CellBuilder::Instance->Create<IInterestRateIndex^> (dynamic_cast<IInterestRateIndex^>(default[index]));
}

void Cephei::QL::Indexes::CInterestRateIndexVector::CItem::set (int index, Cephei::Generic::ICell<Cephei::QL::Indexes::IInterestRateIndex^>^ value) 
{
	default[index] = safe_cast<IInterestRateIndex^>(value->Value);
}
#ifdef STRUCT
std::vector<QuantLib::InterestRateIndex>& Cephei::QL::Indexes::CInterestRateIndexVector::GetReference ()
{
	 return *_pVValue;
}
#endif

std::vector<boost::shared_ptr<QuantLib::InterestRateIndex>>& Cephei::QL::Indexes::CInterestRateIndexVector::GetShared ()
{
	return *_pVBoost;
}

#ifdef HANDLE
std::vector<QuantLib::Handle<QuantLib::InterestRateIndex>>& Cephei::QL::Indexes::CInterestRateIndexVector::GetHandle ()
{
	return *_pVHand;
}
#endif
bool Cephei::QL::Indexes::CInterestRateIndexVector::PrepareFeature (NativeFeature feature)
{
	switch (feature)
	{
#ifdef STRUCT
		case NativeFeature::Value :
			if (_pVValue == NULL)
			{
				_pVValue = new std::vector<QuantLib::InterestRateIndex> ();
				return true;
			}
			break;
#endif
        case NativeFeature::shared_ptr :
			if (_pVBoost == NULL)
			{
				_pVBoost = new std::vector<boost::shared_ptr<QuantLib::InterestRateIndex>> ();
				return true;
			}
			break;
#ifdef HANDLE
        case NativeFeature::Handle :
            if (_pVHand == NULL)
            {
                _pVHand = new std::vector<QuantLib::Handle<QuantLib::InterestRateIndex>> ();
                return true;
            }
            break;
#endif
	}
	return false;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

/* <summary>Create a single dimension array of InterestRateIndex that can be passed into other function </summary> */
IVector<Cephei::QL::Indexes::IInterestRateIndex^>^ Cephei::QL::Indexes::CInterestRateIndex_Factory::CreateVector ()
 {
	 return gcnew CoVector<IInterestRateIndex^> (gcnew CInterestRateIndexVector ());
 }
IVector<Cephei::QL::Indexes::IInterestRateIndex^>^ Cephei::QL::Indexes::CInterestRateIndex_Factory::CreateVector (System::Collections::Generic::IEnumerable<IInterestRateIndex^>^ source)
 {
	 return gcnew CoVector<IInterestRateIndex^> (source, gcnew CInterestRateIndexVector ());
 }
/* <summary>Create a single dimension array of InterestRateIndex with change events</summary> */
Cephei::Generic::ICell<IVector<Cephei::Generic::ICell<Cephei::QL::Indexes::IInterestRateIndex^>^>^>^ Cephei::QL::Indexes::CInterestRateIndex_Factory::CreateCellVector ()
 {
	 return CellBuilder::Instance->Create<IVector<Cephei::Generic::ICell<Cephei::QL::Indexes::IInterestRateIndex^>^>^> (gcnew CoCellVector<Cephei::Generic::ICell<Cephei::QL::Indexes::IInterestRateIndex^>^> (gcnew CInterestRateIndexVector ()));
 }
Cephei::Generic::ICell<IVector<Cephei::Generic::ICell<Cephei::QL::Indexes::IInterestRateIndex^>^>^>^ Cephei::QL::Indexes::CInterestRateIndex_Factory::CreateCellVector (System::Collections::Generic::IEnumerable<Cephei::Generic::ICell<Cephei::QL::Indexes::IInterestRateIndex^>^>^ source)
 {
	 return CellBuilder::Instance->Create<IVector<Cephei::Generic::ICell<Cephei::QL::Indexes::IInterestRateIndex^>^>^> (gcnew CoCellVector<Cephei::Generic::ICell<Cephei::QL::Indexes::IInterestRateIndex^>^> (source, gcnew CInterestRateIndexVector ()));
 }

